<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['extradata']=array();
$return['diy']=$this->plugin_setting('diy');
$basic=$this->plugin_setting('basic');
$basic['quan_desc']=$basic['quan_desc']?$basic['quan_desc']:'物流圈，分享时时动态，了解周边货运物流信息！这里有全国各地的货运物流供求信息...';
if($_RQ['op']=='main'){
	$quanid = intval($_RQ['quanid']);
	$this->session('quanid',$quanid);
	$snsid = intval($_RQ['snsid']);
	$this->session('snsid',$snsid);
	$fromuser = intval($_RQ['fromuser']);
	$pcd_code = intval($_RQ['pcd_code']);
	$this->session('fromuser',$fromuser);
	$notice = intval($_RQ['notice']);
	$this->session('notice',$notice);
	if($pcd_code && !$snsid && !$notice){
		$return['pcd']=cfc('area')->get_pcd_array($pcd_code);
		$return['params']=array();
		$return['upsns']=true;
		exi($return);
	}
	if(!$quanid && $basic['issns'] && !$snsid  && !$notice){
		$return['params']=array();
		$return['upsns']=true;
		$return['pcd']=array();
		exi($return);
	}
	if($quanid){
		$this->model()->add_member(0,intval($_RQ['fromuser']),0,$quanid);
		$return['likesnum']=pdo_getsum('jy_wuliu_item',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'mid'=>$quanid),'likes');
		$return['looksnum']=pdo_getsum('jy_wuliu_item',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'mid'=>$quanid),'looks');
		$return['jielinum']=pdo_count('jy_wuliu_item_jieli',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$quanid),'id');
		$return['fensnum']=pdo_count('jy_wuliu_userlog',array('uniacid'=>$_SESSION['uniacid'],'isfollow'=>1,'userid'=>$quanid),'id');
		$member = pdo_get('jy_wuliu_member',array('mid'=>$quanid,'uniacid'=>$_SESSION['uniacid']),array('logo','title','desc','pcd'));
		$return['quaninfo']=$member;
		$htmltitle = $member['title'];
		$share_desc = $member['desc'];
		$share_image = $member['logo'];
		$return['isfans']=pdo_getcolumn('jy_wuliu_userlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'userid'=>$quanid),'isfollow');
		//进入圈详情，记录访问者浏览信息
		$islook=pdo_get('jy_wuliu_quanlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'quanid'=>$quanid));
		if(empty($islook)){
			$insert=array(
				'uniacid'=>$_SESSION['uniacid'],
				'quanid'=>$quanid,
				'mid'=>$_SESSION['uid'],
				'createtime'=>TIMESTAMP
			);
			pdo_insert('jy_wuliu_quanlog',$insert);
		}else{
			pdo_update('jy_wuliu_quanlog',array('createtime'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'quanid'=>$quanid));
		}
		$return['sharedata']=array(
			'title'=>$htmltitle?:'物流圈',
			'desc'=>$share_desc,
			'link'=>custom_url('jy_wuliu/index//quanid='.$quanid.'&current_plugin='.$_SESSION['current_plugin'],true),
			'imgUrl'=>tomedia($share_image?:'../addons/jy_wuliu/resource/images/ico-wuliu.png'),
		);
	}else{
		if($basic['issns']  && !$notice){
				//进入圈详情，记录访问者浏览信息
				$islook=pdo_get('jy_wuliu_quanlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'snsid'=>$snsid));
				if(empty($islook)){
					$insert=array(
						'uniacid'=>$_SESSION['uniacid'],
						'snsid'=>$snsid,
						'mid'=>$_SESSION['uid'],
						'createtime'=>TIMESTAMP
					);
					pdo_insert('jy_wuliu_quanlog',$insert);
				}else{
					pdo_update('jy_wuliu_quanlog',array('createtime'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'snsid'=>$snsid));
				}
				$this->model()->add_member(0,intval($_RQ['fromuser']),$snsid);
				$return['likesnum']=pdo_getsum('jy_wuliu_item',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'snsid'=>$snsid),'likes');
				$return['looksnum']=pdo_getsum('jy_wuliu_item',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'snsid'=>$snsid),'looks');
				$return['jielinum']=pdo_count('jy_wuliu_item_jieli',array('uniacid'=>$_SESSION['uniacid'],'snsid'=>$snsid),'id');
				$return['fensnum']=pdo_count('jy_wuliu_userlog',array('uniacid'=>$_SESSION['uniacid'],'snsid'=>$snsid,'isfollow'=>1),'id');
				$sns=pdo_get('jy_wuliu_sns',array('uniacid'=>$_SESSION['uniacid'],'id'=>$snsid));
				$sns['desc']=$basic['quan_desc'];
				$sns['logo']=$sns['logo']?$sns['logo']:$basic['logo'];
				$return['quaninfo']=$sns;
				$htmltitle = $sns['title'];
				$share_desc = $sns['desc'];
				$share_image = $sns['logo'];
				$return['isfans']=pdo_getcolumn('jy_wuliu_userlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'snsid'=>$snsid),'isfollow');
		}else{
			$this->model()->add_member(0,intval($_RQ['fromuser']));
			$return['likesnum']=pdo_getsum('jy_wuliu_item',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),'likes');
			$return['looksnum']=pdo_getsum('jy_wuliu_item',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),'looks');
			$return['jielinum']=pdo_count('jy_wuliu_item_jieli',array('uniacid'=>$_SESSION['uniacid']),'id');
			$return['fensnum']=pdo_count('jy_wuliu_userlog',array('uniacid'=>$_SESSION['uniacid'],'snsid'=>$snsid,'isfollow'=>1),'id');
			$return['quaninfo']=array(
					'title'=>$basic['title'],
					'logo'=>$basic['logo'],
					'pcd'=>$basic['pcd'],
					'desc'=>$basic['desc'],
			);
			$htmltitle = $basic['title'];
			$share_desc = $basic['share_desc'];
			$share_image = $basic['share_image'];
			$return['isfans']=pdo_getcolumn('jy_wuliu_userlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'snsid'=>$snsid),'isfollow');
		}
		$this->model('model')->upsnslook($snsid,$fromuser);
		if($return['quaninfo']['bossmid']){
			$return['quaninfo']['adds']=pdo_getcolumn('jy_wuliu_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$return['quaninfo']['bossmid']),'adds');
			$return['quaninfo']['adds']=json_decode($return['quaninfo']['adds'],true);
		}
		$return['sharedata']=array(
			'title'=>$htmltitle?:'物流圈',
			'desc'=>$share_desc,
			'link'=>custom_url('jy_wuliu/index//snsid='.$snsid.'&fromuser='.$_SESSION['uid'].'&current_plugin='.$_SESSION['current_plugin'],true),
			'imgUrl'=>tomedia($share_image?:'../addons/jy_wuliu/resource/images/ico-wuliu.png'),
		);
	}
	//获取流量IP
	$return['quaninfo']['mysum']=pdo_getsum('jy_wuliu_looklog',array('uniacid'=>$_SESSION['uniacid'],'fromuser'=>$_SESSION['uid']),'looks');
	if($return['quaninfo']['bossmid']){
		$return['isboss']=$return['quaninfo']['bossmid']==$_SESSION['uid']?1:0;
		$return['quaninfo']['bosssum']=pdo_getsum('jy_wuliu_looklog',array('uniacid'=>$_SESSION['uniacid'],'fromuser'=>$return['quaninfo']['bossmid']),'looks');	
	}
	//是否关注
	$return['isfollow']=pdo_getcolumn('core_fans',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'follow');
	$return['quanid']=$quanid;
	$return['snsid']=$snsid;
	$return['notices']=pdo_getall('core_account_article',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1'),'','id desc');
	$return['member']=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('createtime','credit1','credit2','mobile','avatar','nickname'));
	set_html('title',$htmltitle?:'物流圈');
	$return['params']['page'] =1;
	exi($return);
}	
if($_RQ['op']=='getlist'){
	$quanid = $this->session('quanid');
	$snsid = $this->session('snsid');
	$notice = $this->session('notice');
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	if($quanid){
		$params['mid']=$quanid;
	}elseif($snsid){
		$params['snsid']=$snsid;
	}elseif($notice){
		$params['snsid']=0;
	}else{
		$params['mid']=$basic['adminuid'];
	}
	if($_RQ['keyword']){
		if(is_numeric($_RQ['keyword'])){
			$params['id']=intval($_RQ['keyword']);
			$return['params']['id']=intval($_RQ['keyword']);
		}else{
			$params['title like']='%'.$_RQ['keyword'].'%';
			$return['params']['title']=$_RQ['keyword'];
		}
	}
	if($_RQ['type']){
		$params['type']=intval($_RQ['type']);
	}
	//按点赞数排序作品
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_wuliu_item',$params,array($pindex,$psize),$total,$fields,'','totop desc, createtime desc');
	if($list){
		$sum=count($list);
		foreach($list as &$item){
			$item['title']=explode('&#8644',$item['title']);
			$item['content'] = json_decode($item['content'],true);
			if($item['content']){
				$img3=0;
				$img10=0;
				$video=0;
				foreach($item['content'] as $k=>$cv){
					if($cv['type']==3){
						$img3 +=1;
						if($img3>1){
							unset($item['content'][$k]);
						}
					}
					if($cv['type']==10){
						$img10 +=1;
						if($img10>1){
							unset($item['content'][$k]);
						}
					}
					if($cv['type']==11){
						$video +=1;
						if($video>1){
							unset($item['content'][$k]);
						}
					}
				}
			}
			$item['fileds'] = json_decode($item['fileds'],true);
			$item['fee']=array();
			if(!empty($item['fileds'])){
				foreach($item['fileds'] as &$fv){
					if(!empty($fv)){
						foreach($fv as $f){
							if(!empty($f)){
								if($f['type']==18){
									$item['fee'][]['value']=price($f['data']);
								}
							}
						}
					}
				}
			}
			paixu($item['fee'],'value');
			$item['diyform'] = json_decode($item['diyform'],true);
			$item['onlinetime']=$item['onlinetime']?$item['onlinetime']:$item['createtime']+7*24*3600;
			$item['endstatus']=$item['onlinetime']>time()?1:0;
			$item['onlinetime2']=$this->model()->date($item['onlinetime']-TIMESTAMP);
			$item['onlinetime']=date('Y-m-d H:i:s',$item['onlinetime']);
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['isme']=$item['mid']==$_SESSION['uid'] ? 1 :0;
			$item['isgetred']=pdo_getcolumn('jy_wuliu_redlog',array('pid'=>$item['id'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>1),'id');
			$item['typetitle']=$this->item_types[$item['type']];
			$item['member']=pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','avatar','nickname'));
			$item['jielinum']=pdo_count('jy_wuliu_item_jieli',array('uniacid'=>$_SESSION['uniacid'],'pid'=>$item['id']),'id');
			$item['msgnum']=pdo_count('jy_wuliu_item_msg',array('uniacid'=>$_SESSION['uniacid'],'pid'=>$item['id']),'id');
			$item['jieli']=pdo_getall('jy_wuliu_item_jieli',array('uniacid'=>$_SESSION['uniacid'],'pid'=>$item['id']),'','createtime desc');
			$item['msg']=pdo_getall('jy_wuliu_item_msg',array('checked'=>'1','uniacid'=>$_SESSION['uniacid'],'pid'=>$item['id']),'','createtime desc');
			if($item['msg']){
				foreach($item['msg'] as &$m){
					$m['createtime'] = date('Y-m-d H:i',$m['createtime']);
					$m['member'] = pdo_get('core_members',array('id'=>$m['mid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','avatar','nickname'));
				}
			}
			if($item['jieli']){
				foreach($item['jieli'] as &$j){
					$j['createtime'] = date('Y-m-d H:i',$j['createtime']);
					$j['member'] = pdo_get('core_members',array('id'=>$j['mid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','avatar','nickname'));
				}
			}
			$item['likes'] = pdo_getall('jy_wuliu_item_like',array('uniacid'=>$_SESSION['uniacid'],'pid'=>$item['id']));
			if($item['likes']){
				foreach($item['likes'] as &$liv){
					$liv['member'] = pdo_get('core_members',array('id'=>$liv['mid'],'uniacid'=>$_SESSION['uniacid']),array('avatar','nickname'));
				}
			}
			$item['isshoucang']=pdo_getcolumn('jy_wuliu_shoucang',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid'=>$item['id']),'isshoucang');
			$item['merch']=pdo_get('jy_wuliu_member',array('mid'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('id','title','desc','logo','wprice1','wprice2','vprice1','vprice2','jprice'));
			//$item['goods']['merchname']=pdo_getcolumn('jy_merch_user',array('id'=>$item['goods']['merchid'],'uniacid'=>$_SESSION['uniacid']),'merchname');
		}
	}
	$return['list']=$list;
	$return['params']['page'] =$pindex;
	exi($return);
}
if($_RQ['op']=='upsns'){
	$fromuser = $this->session('fromuser');
	$postdata=get_postdata();
	$pcd = $postdata['pcd'];
	$pcd['district']=$pcd['district']?$pcd['district']:$pcd['street'];
	if($pcd['province'] && $pcd['city'] && $pcd['district']){
		$postpcd = trim($pcd['province']).trim($pcd['city']).trim($pcd['district']);
		$sns = pdo_getall('jy_wuliu_sns',array('uniacid'=>$_SESSION['uniacid']));
		if($sns){
			foreach($sns as $k=>$item){
				$sndpcd = json_decode($item['pcd'],true);
				$sndpcdinfo = trim($sndpcd['province']).trim($sndpcd['city']).trim($sndpcd['district']);
				if($postpcd == $sndpcdinfo){
					$snsid = $item['id'];
					$snsinfo = $sns[$k];
					$snsinfo['pcd']=json_decode($snsinfo['pcd'],true);
				}
			}
		}
		if(empty($snsinfo)){
			$pcd = array('province'=>$pcd['province'],'city'=>$pcd['city'],'district'=>$pcd['district']);
			$insert=array(
					'uniacid'=>$_SESSION['uniacid'],
					'title'=>trim($pcd['district']),
					'desc'=>trim($pcd['district']).$basic['quan_desc'],
					'pcd'=>ijson_encode($pcd),
					'status'=>1,
					'createtime'=>TIMESTAMP
			);
			pdo_insert('jy_wuliu_sns',$insert);
			$snsid=pdo_insertid();
			$snsinfo = pdo_get('jy_wuliu_sns',array('uniacid'=>$_SESSION['uniacid'],'id'=>$snsid));
			
		}
		$snsinfo['desc']=$basic['quan_desc'];
		$htmltitle = $snsinfo['title'];
		$share_title = $snsinfo['desc'];
		$share_image = $snsinfo['logo']?$snsinfo['logo']:$basic['logo'];
	}else{
		$snsid = $this->session('snsid');
		$this->session('notice',1);
		$htmltitle = $basic['title'];
		$share_title = $basic['share_desc'];
		$share_image = $basic['share_image'];
		$snsinfo=array(
					'title'=>$basic['title'],
					'logo'=>$basic['logo'],
					'pcd'=>$basic['pcd'],
					'desc'=>$basic['desc'],
		);
	}
	$pcd2 = ijson_encode($pcd);
	$this->model()->add_member(0,intval($fromuser),$snsid,'',$pcd2);
	$return['likesnum']=pdo_getsum('jy_wuliu_item',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'snsid'=>$snsid),'likes');
	$return['looksnum']=pdo_getsum('jy_wuliu_item',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'snsid'=>$snsid),'looks');
	$return['jielinum']=pdo_count('jy_wuliu_item_jieli',array('uniacid'=>$_SESSION['uniacid'],'snsid'=>$snsid),'id');
	$return['fensnum']=pdo_count('jy_wuliu_userlog',array('uniacid'=>$_SESSION['uniacid'],'snsid'=>$snsid,'isfollow'=>1),'id');
	
	//是否关注
	$return['isfollow']=pdo_getcolumn('core_fans',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'follow');
	$return['isfans']=pdo_getcolumn('jy_wuliu_userlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'snsid'=>$snsid),'isfollow');
	$return['notices']=pdo_getall('core_account_article',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1'),'','id desc');
	$return['member']=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('createtime','credit1','credit2','mobile','avatar','nickname'));
	set_html('title',$htmltitle?:'物流圈');
	$return['sharedata']=array(
		'title'=>$htmltitle?:'物流圈',
		'desc'=>$share_title,
		'link'=>custom_url('jy_wuliu/index//snsid='.$snsid.'&fromuser='.$_SESSION['uid'].'&current_plugin='.$_SESSION['current_plugin'],true),
		'imgUrl'=>tomedia($share_image?:'../addons/jy_wuliu/resource/images/ico-wuliu.png'),
	);
	//进入圈详情，记录访问者浏览信息
	$islook=pdo_get('jy_wuliu_quanlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'snsid'=>$snsid));
	if(empty($islook)){
			$insert=array(
				'uniacid'=>$_SESSION['uniacid'],
				'snsid'=>$snsid,
				'mid'=>$_SESSION['uid'],
				'createtime'=>TIMESTAMP
			);
			pdo_insert('jy_wuliu_quanlog',$insert);
	}else{
			pdo_update('jy_wuliu_quanlog',array('createtime'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'snsid'=>$snsid));
	}
	if($snsid){
		$this->model('model')->upsnslook($snsid,$fromuser);
		if($snsinfo['bossmid']){
			$return['quaninfo']['adds']=pdo_getcolumn('jy_wuliu_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$snsinfo['bossmid']),'adds');
			$return['quaninfo']['adds']=json_decode($return['quaninfo']['adds'],true);
		}
	}
	$return['params']['page'] =1;
	$return['snsid']=$snsid;
	$snsinfo['logo'] = $snsinfo['logo']?$snsinfo['logo']:$basic['logo'];
	$return['quaninfo']=$snsinfo;
	//获取流量IP
	$return['quaninfo']['mysum']=pdo_getsum('jy_wuliu_looklog',array('snsid'=>$snsid,'uniacid'=>$_SESSION['uniacid'],'fromuser'=>$_SESSION['uid']),'looks');
	if($return['quaninfo']['bossmid']){
		$return['isboss']=$return['quaninfo']['bossmid']==$_SESSION['uid']?1:0;
		$return['quaninfo']['bosssum']=pdo_getsum('jy_wuliu_looklog',array('snsid'=>$snsid,'uniacid'=>$_SESSION['uniacid'],'fromuser'=>$return['quaninfo']['bossmid']),'looks');	
	}
	$this->session('snsid',$snsid);
	$return['upsns']=false;
	exi($return);
}
if($_RQ['op']=='setmsg'){
	$postdata=get_postdata();
	$snsid = $this->session('snsid');
	$item=pdo_get('jy_wuliu_item',array('uniacid'=>$_SESSION['uniacid'],'id'=>intval($postdata['pid'])));
	$checked = $basic['msg_shenhe']?0:1;
	$data=array(
		'title'=>trim($postdata['msg']),
		'images'=>ijson_encode($postdata['images']),
		'mid'=>$_SESSION['uid'],
		'pid'=>intval($postdata['pid']),
		'uniacid'=>$_SESSION['uniacid'],
		'createtime'=>time(),
		'checked'=>$checked,
		'type'=>$item['type'],
	);
	pdo_insert('jy_wuliu_item_msg',$data);
	if($checked){
		exi('评论成功！等待审核！');
	}else{
		exi('评论成功！');
	}
}
if($_RQ['op']=='follow'){
	$quanid = $this->session('quanid');
	$snsid = $this->session('snsid');
	if(!$quanid && !$snsid){
		exi('没有找到该圈，请重新选择！','error');
	}
	if($quanid){
		$follow=pdo_get('jy_wuliu_userlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'userid'=>$quanid));
		if($follow){
			if($follow['isfollow'] !=1){
				pdo_update('jy_wuliu_userlog',array('isfollow'=>1,'createtime'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'userid'=>$quanid));
				exi('关注成功');
			}else{
				pdo_update('jy_wuliu_userlog',array('isfollow'=>0),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'userid'=>$quanid));
				exi('已取消关注');
			}
		}else{
			$insert=array(
				'uniacid'=>$_SESSION['uniacid'],
				'userid'=>$quanid,
				'mid'=>$_SESSION['uid'],
				'isfollow'=>1,
				'createtime'=>TIMESTAMP
			);
			pdo_insert('jy_wuliu_userlog',$insert);
		}
	}else{
		$follow=pdo_get('jy_wuliu_userlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'snsid'=>$snsid));
		if($follow){
			if($follow['isfollow'] !=1){
				pdo_update('jy_wuliu_userlog',array('isfollow'=>1,'createtime'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'snsid'=>$snsid));
				exi('关注成功');
			}else{
				pdo_update('jy_wuliu_userlog',array('isfollow'=>0),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'snsid'=>$snsid));
				exi('已取消关注');
			}
		}else{
			$insert=array(
				'uniacid'=>$_SESSION['uniacid'],
				'snsid'=>$snsid,
				'mid'=>$_SESSION['uid'],
				'isfollow'=>1,
				'createtime'=>TIMESTAMP
			);
			pdo_insert('jy_wuliu_userlog',$insert);
		}
	}
	exi('关注成功');
}
if($_RQ['op']=='shoucang'){
	$postdata=get_postdata();
	$id = intval($postdata['pid']);
	if(!$id){
		exi('没有找到该帖子，请重新选择！','error');
	}
	$shoucang=pdo_get('jy_wuliu_shoucang',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid'=>$id));
	if($shoucang){
		if($shoucang['isshoucang'] !=1){
			pdo_update('jy_wuliu_shoucang',array('isshoucang'=>1,'createtime'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid'=>$id));
			exi('收藏成功');
		}else{
			pdo_update('jy_wuliu_shoucang',array('isshoucang'=>0),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid'=>$id));
		   exi('取消收藏');
		}
	}else{
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'pid'=>$id,
			'mid'=>$_SESSION['uid'],
			'isshoucang'=>1,
			'createtime'=>TIMESTAMP
		);
		pdo_insert('jy_wuliu_shoucang',$insert);
	}
	exi('收藏成功');
}
if($_RQ['op']=='del'){
	if(!$_RQ['id']){
		exi('帖子不存在哦！','error');
	}
	pdo_delete('jy_wuliu_item',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	exi('删除成功！');
}
if($_RQ['op']=='totop'){
	$snsid = $this->session('snsid');
	if(!$_RQ['id']){
		exi('帖子不存在哦！','error');
	}
	$item=pdo_get('jy_wuliu_item',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']),array('totop','snsid'));
	$snsinfo=pdo_get('jy_wuliu_sns',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['snsid']),array('title','bossmid'));
	if($snsinfo['bossmid']!=$_SESSION['uid']){
		exi('您不是该主题的圈主！','error');
	}
	$topsum=pdo_count('jy_wuliu_item',array('uniacid'=>$_SESSION['uniacid'],'snsid'=>$item['snsid'],'totop'=>1),'id');
	if($topsum>0){
		pdo_update('jy_wuliu_item',array('totop'=>0),array('uniacid'=>$_SESSION['uniacid'],'snsid'=>$item['snsid']));
		pdo_update('jy_wuliu_item',array('totop'=>1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		exi('您已经置顶了一条主题，已替换置顶！','/index/main/snsid='.$snsid);
	}else{
		pdo_update('jy_wuliu_item',array('totop'=>1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		exi('置顶成功！','/index/main/snsid='.$snsid);
	}
}
if($_RQ['op']=='setboss'){
	$snsid = $this->session('snsid');
	$oldbossmid=pdo_getcolumn('jy_wuliu_sns',array('id'=>$snsid,'uniacid'=>$_SESSION['uniacid']),'bossmid');
	if($oldbossmid){
		//获取流量IP
		$return['quaninfo']['mysum']=pdo_getsum('jy_wuliu_looklog',array('snsid'=>$snsid,'uniacid'=>$_SESSION['uniacid'],'fromuser'=>$_SESSION['uid']),'looks');
		if($return['quaninfo']['bossmid']){
			$return['quaninfo']['bosssum']=pdo_getsum('jy_wuliu_looklog',array('snsid'=>$snsid,'uniacid'=>$_SESSION['uniacid'],'fromuser'=>$return['quaninfo']['bossmid']),'looks');	
		}
		if($return['quaninfo']['mysum']>$return['quaninfo']['bosssum']+10){
			pdo_update('jy_wuliu_sns',array('bossmid'=>$_SESSION['uid']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$snsid));
			cfc('message')->setnoticelog('您的圈主身份已被他人抢夺！分享带来更多访问，可抢回圈主！',0,'',$oldbossmid);
		}else{
			exi('您没有权限成为圈主（只有带来访问第一的才能成为圈主噢！）','error');
		}
	}else{
		pdo_update('jy_wuliu_sns',array('bossmid'=>$_SESSION['uid']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$snsid));

	}
	exi('恭喜您成为圈主！');
}
if($_RQ['op']=='getnotice'){
	$log=cfc('message')->getonelog();
	exi($log['msg']);
}